<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\common\service\ShumaiApiService;

/**
 * 公司认证接口
 */
class CompanyAuth extends Api
{

    // 无需登录的接口,*表示全部
    protected $noNeedLogin = ['*'];
    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = ['*'];

    /**
     * 企业四要素校验
     *
     * @ApiTitle    (企业四要素校验)
     * @ApiSummary  (企业四要素校验)
     * @ApiMethod   (POST)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="company_name", type="string", required=true, description="公司名称")
     * @ApiParams   (name="credit_no", type="string", required=true, description="统一信用代码")
     * @ApiParams   (name="legal_person", type="string", required=true, description="法人姓名")
     * @ApiParams   (name="id_card", type="string", required=true, description="法人身份证号")
     * @ApiReturn   ({
            "msg": "返回成功",
            "code": 200,
            "data": {
                "orderNo": "331698455182722374",
                "companyName": true,//公司名称是否一致
                "creditNo": true,//统一信用代码是否一致
                "legalPerson": true,//法人姓名是否一致
                "idCard": true//身份证号是否一致
            }
        })
     */
    public function company4Check()
    {
        $companyName = $this->request->post('company_name');
        $creditNo = $this->request->post('credit_no');
        $legalPerson = $this->request->post('legal_person');
        $idCard = $this->request->post('id_card');
        if (empty($companyName) || empty($creditNo) || empty($legalPerson) || empty($idCard)) $this->error('参数错误');
        $shumaiApiService = new ShumaiApiService();
        $result = $shumaiApiService->companyFourElementCheck($companyName, $creditNo, $legalPerson, $idCard);
        if (0 === $result['code']) {
            $this->error($result['msg']);
        }
        $this->success('返回成功', $result['data']);
    }

    /**
     * 企业三要素校验
     *
     * @ApiTitle    (企业三要素校验)
     * @ApiSummary  (企业三要素校验)
     * @ApiMethod   (POST)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="company_name", type="string", required=true, description="公司名称")
     * @ApiParams   (name="credit_no", type="string", required=true, description="统一信用代码")
     * @ApiParams   (name="legal_person", type="string", required=true, description="法人姓名")
     * @ApiReturn   ({
            "msg": "返回成功",
            "code": 200,
            "data": {
                "orderNo": "331698455182722374",
                "companyName": true,//公司名称是否一致
                "creditNo": true,//统一信用代码是否一致
                "legalPerson": true,//法人姓名是否一致
            }
        })
     */
    public function company3Check()
    {
        $companyName = $this->request->post('company_name');
        $creditNo = $this->request->post('credit_no');
        $legalPerson = $this->request->post('legal_person');
        if (empty($companyName) || empty($creditNo) || empty($legalPerson)) $this->error('参数错误');
        $shumaiApiService = new ShumaiApiService();
        $result = $shumaiApiService->companyThreeElementCheck($companyName, $creditNo, $legalPerson);
        if (0 === $result['code']) {
            $this->error($result['msg']);
        }
        $this->success('返回成功', $result['data']);
    }
}
